/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app;

import java.io.*;

public class Settings {
    private static final String lineSeparator = System.getProperty("line.separator");
    private static final String path = System.getProperty("user.dir") + "\\settings.txt";
    private static final Settings settings = loadSettings();
    private int askTime = 1800000;
    private int answerTime = 30000;
    
    
    private Settings() { }
    
    public static Settings getSettings() {
        return settings;
    }
    
    private static Settings loadSettings() {
        Settings result = null;
        BufferedReader reader = null;
        
        try {
            reader = new BufferedReader(new FileReader(path));
            result = new Settings();
            
            result.askTime = Integer.parseInt(reader.readLine());
            result.answerTime = Integer.parseInt(reader.readLine());
        }
        catch (Exception e) {
            System.err.println("Błąd podczas wczytywania ustawień.");
            result = new Settings();
        }
        finally {
            if (reader != null) {
                try {
                    reader.close();
                }
                catch (Exception e) {
                    System.err.println("Błąd podczas kończenia wczytywania ustawień.");
                }
            }
        }
        
        return result;
    }
    
    public void Save() {
        BufferedWriter writer = null;
        
        try {
            writer = new BufferedWriter(new FileWriter(path, false));
            
            writer.append(askTime + lineSeparator);
            writer.append(answerTime + lineSeparator);
        }
        catch (Exception e) {
            System.err.println("Błąd podczas zapisywania ustawień.");
        }
        finally {
            if (writer != null) {
                try {
                    writer.close();
                }
                catch (Exception e) {
                    System.err.println("Błąd podczas kończenia zapisywania ustawień.");
                }
            }
        }
    }
    
    
    public int getAskTime() {
        return askTime;
    }
    
    public void setAskTime(int value) {
        askTime = value;
    }
    
    public int getAnswerTime() {
        return answerTime;
    }
    
    public void setAnswerTime(int value) {
        answerTime = value;
    }
}
